import React,{useState} from 'react';
import './Top.scss'
import {useRequest} from 'alova/client'
import {get_user} from "../../api/api.js";
import PropTypes from 'prop-types'
function Top(props) {
    const {data,send,onSuccess} = useRequest(get_user,{
        initialData: [], //默认数据
        immediate: false //关闭自动请求
    })
    onSuccess(({data})=>{
        props.updateList(data)
    })
    const [kwyword,setKeyword] = useState('')
    function getData(){
        send(kwyword)
        setKeyword('')

    }
    return (
        <div className={"search-input"}>
            <div  className={"input"}>
                <input value={kwyword} onChange={e=>setKeyword(e.target.value)} />
            </div>
            <div className={"button"}>
                <button onClick={getData}>搜索</button>
            </div>
        </div>
    );
}
Top.protoType = {
    updateList: PropTypes.func.isRequired
}

export default Top;